import dayjs from 'dayjs';
/**
 * 将 "YYYY-MM-DD HH:mm:ss" 格式的日期字符串转换为时间戳
 * @param datetime 日期字符串
 * @returns 对应的时间戳
 */
export function convertToTimestamp(dateString: string): number {
  const date = dayjs(dateString, 'YYYY-MM-DD HH:mm:ss');
  return date.valueOf();
}

/**
 * 格式化倒计时 MM:SS
 * @param countdown
 * @returns
 */
export function formatCountdown(countdown: number) {
  const totalSeconds = Math.floor(countdown / 1000);
  const minutes = Math.floor(totalSeconds / 60);
  const seconds = totalSeconds % 60;
  return `0${minutes}:${seconds < 10 ? `0${seconds}` : seconds}`;
}
